import AITalk from '../talkTemplate';
import { GetChangedNextStepMethod } from './defination';
const node = AITalk.getTalks('nlp');
/**
 * 获取下一步变更的数据
 * @param { Object } preNex 初始的下一步数据 { other: ''}
 * @param { Object } curNext 当前的下一步数据  { other: ''}
 * @param { Array } preNlpsBranchList 初始的nlp  []
 * @param { Array } curNlpsBranchList 当前的nlp  []
 */
export const getChangedNextStep = (preNext = {}, curNext = {}, preNlpsBranchList = [], curNlpsBranchList = []) => {
	let changedNextSteps = [];
	if (!preNext && !curNext && !preNlpsBranchList && curNlpsBranchList) {
		return [];
	}

	if (preNlpsBranchList.length > curNlpsBranchList.length) {
		// 有删除
		preNlpsBranchList.map((item, index) => {
			if (curNlpsBranchList[index]) {
				if (item.nextStepsNlp !== curNlpsBranchList[index].nextStepsNlp) {
					changedNextSteps.push({
						text: `NLP返回分支${index + 1}`,
						type: `third-nlp${index + 1}`,
						previous: item.nextStepsNlp,
						current: curNlpsBranchList[index].nextStepsNlp
					});
				}
			} else {
				changedNextSteps.splice(0, 0, {
					text: `NLP返回分支${index + 1}`,
					type: `third-nlp${index + 1}`,
					previous: item.nextStepsNlp,
					current: null
				});
			}
		});
	} else {
		// 有新增
		curNlpsBranchList.map((item, index) => {
			if (preNlpsBranchList[index]) {
				if (item.nextStepsNlp !== preNlpsBranchList[index].nextStepsNlp) {
					changedNextSteps.push({
						text: `NLP返回分支${index + 1}`,
						type: `third-nlp${index + 1}`,
						previous: preNlpsBranchList[index].nextStepsNlp,
						current: item.nextStepsNlp
					});
				}
			} else {
				changedNextSteps.push({
					text: `NLP返回分支${index + 1}`,
					type: `third-nlp${index + 1}`,
					previous: null,
					current: item.nextStepsNlp
				});
			}
		});
	}

	if (preNext['other'] !== curNext['other']) {
		changedNextSteps.push({
			text: '识别失败',
			type: node.errorRemind.type,
			previous: preNext['other'],
			current: curNext['other']
		});
	}

	return changedNextSteps;
};
GetChangedNextStepMethod['nlp'] = getChangedNextStep;
